
package com.sihai.ehr.web;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class EHRSessionListener implements HttpSessionListener {
	
	private static int onlineCount = 0;
	
	public static final String USER_ONLINE = "USER_ONLINE";


	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
	 */
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		onlineCount++;
		se.getSession().setAttribute(USER_ONLINE, onlineCount);
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		if(onlineCount > 1){
			onlineCount--;
			se.getSession().removeAttribute(USER_ONLINE);
		}
	}
	
}
